#ifndef __KEYPAD_H__
#define __KEYPAD_H__
#include "common.h"

typedef enum{ IDLE, PRESSED, HOLD, RELEASED } KeyState;

extern unsigned char bitMap[3];

#define NO_KEY '\0'

typedef struct
{
	unsigned char kchar;
	unsigned char kcode;
	KeyState kstate;
	unsigned char stateChanged;
}Key;



#define ROWS	3
#define COLUMNS	4
#define LIST_MAX 3

//#define ROW0	P3_0
//#define ROW1	P3_1
//#define ROW2	P3_2

//#define COLUMN0	P3_4
//#define COLUMN1	P3_5
//#define COLUMN2	P3_6
//#define COLUMN3 P3_7

#define LOW 0
#define HIGH 1
#define OPEN HIGH
#define CLOSED LOW
#define NULL 0

void key_update(unsigned char userKeyChar, KeyState userState, bool userStatus);
unsigned char getKey();
bool getKeys();
void scanKeys();
bool updateList();
void bitWrite(unsigned char *x, unsigned char n, bool b);
bool bitRead(unsigned char x, unsigned char keyChar);
void nextKeyState(unsigned char idx, bool button); 
void transitionTo(unsigned char idx, KeyState nextState);
unsigned char findInList (unsigned char keyChar);


#endif